package com.youjia.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.stereotype.Component;

import java.io.FileWriter;
import java.io.IOException;


/**
 * 支付宝接口配置类
 */
@Component
public class PayConfig {
    // [沙箱环境]应用ID,您的APPID，收款账号既是你的APPID对应支付宝账号
    public static String app_id = "2021000118608816";
    // [沙箱环境]商户私钥，你的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCDDG1JqgElnYYDu1p6VqKskyQp5rEDS3TJ4RaW4Gm9O9Ru347SGer9qqpjCnk3RnhCx8hIMnfzrtRJIZaaVjEvI10SGd0s2LSP5NZAwSDgYA2AW14yszzpV5INUkNC40JPNxN9nvrS5sHvbsYYBAq4ojF+la5fVD8SX+O66VhPYWSIext1zFoV80uHp3Ci0V2oa32M4rf36xC9O6A3fnukkSwmixugIPiZThewxLpfKMh8Y35194xnn3KJlySFymb34b5QrqqAbI53urYX+MQT+iWs7dS/juNTcuBhvBQjjBsssWdkfttIjOAQ4QNZoqqPQ6WLzGa4qC+frcEB5dcjAgMBAAECggEAQTs4U0iqVXz5rnXd7bOeOeTsRWctiYRP2AWQ5v1B5Q4ZCi+Buhdon2gKdE5MVDVhu2wSx81HZCcMSHLNsnlg9iPWOiJhs+cSyeWQuJ7prIZjchcI5pfNpCEQ9EyUaoERCrlRnGA8Xiq7MmGjfWTVqV4i4O3E5HLdClps0yc/7BLKTCapghqWG1454Uh1P7jn8epi7eUOVbXrmJUj3RcuOqa8sD0umUJnDsAgWlJRABQJtmTQ4HMaBqaIVT/4B2bFndMwdHJALTNhmOmt8e/6uFTIzaHuSGkdKPNX8+vkQ6b4X2OvLni2Lzn98LfBggPCTmgSwn0hHYnzfxcipY+xkQKBgQC4jZKAmudJLpYtTVac7aHU+uSydC4QXpBllsTeG1fm726mU9onDuWAzfsGbnkMMAUX6RTY9YhC741jx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jrlrdm+dZ3Qolxxj6BbbgGgXL8M1233Jg8USCW9LT/UWNzt4xTvXColItoK/TrHxVIkYrZKPoN6gkPQKBgAGdMSbJlXriEz4OAhOsxs8ZYXKYVnfRKN7IndRYsHwvEIIIOwwbKkix8uw3OckszwrFzI2wLoBDf+Ls1Qm45fTLgchAWWqPczoO5NLk445IvDAHZ3tt+w/hVfoksnPEXy6S4pgP3lY1wAx8THhFRmTg9IjKQCBoJRpJUWAzkd1BAoGBALC5EXJL+NMPFO+KeBk12NDysdDvZnOFknI2GK6/EwW3dAfvBMXVxHOP54bVKkVW5SB6NOP3457ga547aAS6emJzx6SolZp95CqS3Vm9TPDz0lnsnrtXIRX0kRxddutiLiEI8TyZmhD6c2l3/Ebi6TTMZpas5+obkdbVA0rYZpu1AoGAaCjnc3yZghQnNHNhiQSqeZDmc6NRK2njUwEOnRufctYx8Rw5QBce0nB6g0Vb9vepfES15ERv7UxQ8Jh9E5EdmO3hNCN08JyDx7HxUsycS6p3mWe9Pdxf8//A5orgAPe/VcARxKP56r8wi4+wDIIb27pyAtEZAjYwcZHKdc6a/jk=";
    // [沙箱环境]支付宝公钥
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgwxtSaoBJZ2GA7taelairJMkKeaxA0t0yeEWluBpvTvUbt+O0hnq/aqqYwp5N0Z4QsfISDJ3867USSGWmlYxLyNdEhndLNi0j+TWQMEg4GANgFteMrM86VeSDVJDQuNCTzcTfZ760ubB727GGAQKuKIxfpWuX1Q/El/juulYT2FkiHsbdcxaFfNLh6dwotFdqGt9jOK39+sQvTugN357pJEsJosboCD4mU4XsMS6XyjIfGN+dfeMZ59yiZckhcpm9+G+UK6qgGyOd7q2F/jEE/olrO3Uv47jU3LgYbwUI4wbLLFnZH7bSIzgEOEDWaKqj0Oli8xmuKgvn63BAeXXIwIDAQAB";
            //"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnRJATE3diuCqP4GdaWwDAjCKg4+ideeYwd2kttd2K86gRYh1phewmiIf38KkjMZW4CuyYcTrG8CWsd4cfAwsc2q1th2lGmD/81tPDPonQX4YrFIHQd5ILdZV3brrRANwy0zuv7oxOZbtgWCpL79cDxzePXZHrCiUVL1bCYNOFyPuYKmawMiHPYVkTx5dXDv9zRoqGYuEEyCjpHc+I4mQ+CU2BHDV72eE2Z5c7I5MPM6gMvTxgM77rCohioroWx/xAyAsxTKzBm3GJWWtcB2YE4SHd1I+GDl4xTNYaBVxKqwKM1O0LjdLOSJPlo3cSedRwZqLzHS1gFsM0AJigWy82wIDAQAB";
    //"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnRJATE3diuCqP4GdaWwDAjCKg4+ideeYwd2kttd2K86gRYh1phewmiIf38KkjMZW4CuyYcTrG8CWsd4cfAwsc2q1th2lGmD/81tPDPonQX4YrFIHQd5ILdZV3brrRANwy0zuv7oxOZbtgWCpL79cDxzePXZHrCiUVL1bCYNOFyPuYKmawMiHPYVkTx5dXDv9zRoqGYuEEyCjpHc+I4mQ+CU2BHDV72eE2Z5c7I5MPM6gMvTxgM77rCohioroWx/xAyAsxTKzBm3GJWWtcB2YE4SHd1I+GDl4xTNYaBVxKqwKM1O0LjdLOSJPlo3cSedRwZqLzHS1gFsM0AJigWy82wIDAQAB";

//    // [沙箱环境]商户私钥，你的PKCS8格式RSA2私钥
//    public static String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCbQV0YmtbTdrNmUPwkaNScjkXqi8XpJsMzUB2F/shM6ywGTvqmsF36ERDQomXQJiWCFfe6KriZxyYRv/9ZZPqMX3XMuJc8l8X59I7ZXVQpCezK8yNvT/83CK7Ey6cjPK5IYePuNXnjJ1BZONCDT9GivhZahiIVl8/vlQy4aUlKdI9GiQSZOHSsyj91oaqfTFUwswL6UrbV7B5Z7tOjcaKQ1mrbn7VXPC3Ze5J5AXE9kUimD14m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vm9TPDz0lnsnrtXIRX0kRxddutiLiEI8TyZmhD6c2l3/Ebi6TTMZpas5+obkdbVA0rYZpu1AoGAaCjnc3yZghQnNHNhiQSqeZDmc6NRK2njUwEOnRufctYx8Rw5QBce0nB6g0Vb9vepfES15ERv7UxQ8Jh9E5EdmO3hNCN08JyDx7HxUsycS6p3mWe9Pdxf8//A5orgAPe/VcARxKP56r8wi4+wDIIb27pyAtEZAjYwcZHKdc6a/jk=";
//    // [沙箱环境]支付宝公钥
//    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm0FdGJrW03azZlD8JGjUnI5F6ovF6SbDM1Adhf7ITOssBk76prBd+hEQ0KJl0CYlghX3uiq4mccmEb//WWT6jF91zLiXPJfF+fSO2V1UKQnsyvMjb0//NwiuxMunIzyuSGHj7jV54ydQWTjQg0/Ror4WWoYiFZfP75UMuGlJSnSPRokEmTh0rMo/daGqn0xVMLMC+lK21eweWe7To3GikNZq25+1Vzwt2XuSeQFxPZFIpg9eJh3hga0EreR7VVuevvXpmtLf7nmZ5/YyLDsigk1ZsqY/tdBELYtCGzVlq3x73sSWXY4svdVo0kvuYHtRZKNjMX6hYTvPxpGaE453fQIDAQAB";

    // [沙箱环境]服务器异步通知页面路径
    public static String notify_url = "http://ngrok.sscai.club/alipay/aliPayNotify_url";
    // [沙箱环境]页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String return_url = "http://localhost:8080/#/Callback";

    // [沙箱环境]
    // public static String gatewayUrl = "https://openapi.alipay.com/gateway.do";//项目正式使用后使用
    public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";//使用沙箱环境时使用

    public static String log_path = "D://logs";  //日志文件
    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    //配置
    public static AlipayClient config(){
        AlipayClient alipayClient = new DefaultAlipayClient(gatewayUrl,
                app_id, merchant_private_key, "json",
                charset, alipay_public_key, sign_type);
        return alipayClient;
    }

  // 订单链接
   public static AlipayTradePagePayRequest returnUrl (){
        AlipayTradePagePayRequest alipayPageRequest = new AlipayTradePagePayRequest();
        alipayPageRequest.setReturnUrl(return_url);
        alipayPageRequest.setNotifyUrl(notify_url);
        return  alipayPageRequest;
   }
    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis() + ".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
